home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_Tix.idb / usr / freeware / lib / tix4.1 / demos / samples / CmpImg3.tcl.z / CmpImg3.tcl
Encoding:
Text File  |  1999-01-26  |  2.3 KB  |  87 lines

  1. # Tix Demostration Program
  2. #
  3. # This sample program is structured in such a way so that it can be
  4. # executed from the Tix demo program "widget": it must have a
  5. # procedure called "RunSample". It should also have the "if" statment
  6. # at the end of this file so that it can be run as a standalone
  7. # program using tixwish.
  8.  
  9. # Demonstrates how to use compound images to display icons in a canvas widget.
  10. #
  11.  
  12. proc RunSample {w} {
  13.     set top [frame $w.f -bd 1 -relief raised]
  14.     set box [tixButtonBox $w.b -bd 1 -relief raised]
  15.  
  16.     pack $box -side bottom -fill both
  17.     pack $top -side top -fill both -expand yes
  18.  
  19.     label $top.lab -text "Drag the icons"
  20.     pack $top.lab -anchor c -side top -pady 4
  21.  
  22.     # Create the canvas to display the icons
  23.     #
  24.     set c [canvas $top.c -relief sunken -bd 1]
  25.     pack $c -side top -expand yes -fill both -padx 4 -pady 4
  26.  
  27.     # create several compound images in the canvas
  28.     #
  29.     set network  [tix getimage network]
  30.     set harddisk [tix getimage harddisk]
  31.  
  32.     set cmp_1 [image create compound -window $c -bd 1]
  33.     $cmp_1 add image -image $network
  34.     $cmp_1 add line
  35.     $cmp_1 add text   -text " Network "
  36.  
  37.     set cmp_2 [image create compound -window $c -bd 1]
  38.     $cmp_2 add image -image $harddisk
  39.     $cmp_2 add line
  40.     $cmp_2 add text   -text " Hard disk "
  41.  
  42.     set cmp_3 [image create compound -window $c -bd 1 \
  43.     -background #c0c0ff -relief raised \
  44.     -showbackground 1]
  45.     $cmp_3 add image -image $network
  46.     $cmp_3 add line
  47.     $cmp_3 add text   -text  " Network 2 "
  48.  
  49.     $c create image  50  50  -image $cmp_1
  50.     $c create image 150  50  -image $cmp_2
  51.     $c create image 250  50  -image $cmp_3
  52.  
  53.     bind $c <1>         "itemStartDrag $c %x %y"
  54.     bind $c <B1-Motion> "itemDrag $c %x %y"
  55.  
  56.     # Create the buttons
  57.     #
  58.     $box add ok     -text Ok     -command "destroy $w" -width 6
  59.     $box add cancel -text Cancel -command "destroy $w" -width 6
  60. }
  61.  
  62.  
  63. proc itemStartDrag {c x y} {
  64.     global lastX lastY
  65.     $c raise current
  66.  
  67.     set lastX [$c canvasx $x]
  68.     set lastY [$c canvasy $y]
  69. }
  70.  
  71. proc itemDrag {c x y} {
  72.     global lastX lastY
  73.     set x [$c canvasx $x]
  74.     set y [$c canvasy $y]
  75.     $c move current [expr $x-$lastX] [expr $y-$lastY]
  76.     set lastX $x
  77.     set lastY $y
  78. }
  79.  
  80. if {![info exists tix_demo_running]} {
  81.     wm withdraw .
  82.     set w .demo
  83.     toplevel $w
  84.     RunSample $w
  85.     bind $w <Destroy> exit
  86. }
  87.